package ch.nortgram.countdown_worldcup_2014.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import ch.nortgram.countdown_worldcup_2014.BaseActivity;
import ch.nortgram.countdown_worldcup_2014.R;

public class FragmentChangeActivity extends BaseActivity
	{
    
	private Fragment mContent;
	
    public FragmentChangeActivity()
    	{
        super(R.string.actionbar_title);
    	}

    @Override
    public void onCreate(Bundle savedInstanceState)
    	{
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null)
            {
        	mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
            }
        if (mContent == null)
        	{
        	mContent = new CountdownFragment();  
        	}

        setContentView(R.layout.activity_countdown);
        getSupportFragmentManager().beginTransaction().replace(R.id.layout_root, mContent).commit();
        getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, new SlidingMenuFragment()).commit();
        
		setSlidingActionBarEnabled(false);
    	}

    @Override
    public void onSaveInstanceState(Bundle outState)
    	{
        super.onSaveInstanceState(outState);
        getSupportFragmentManager().putFragment(outState, "mContent", mContent);
    	}

    public void switchContent(Fragment fragment)
    	{
        // the meat of switching fragment
        mContent = fragment;
        getSupportFragmentManager().beginTransaction().replace(R.id.layout_root, fragment).commit();
        getSlidingMenu().showContent();
    	}

	}